<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

//-----------------------------------------------------------------
//  Filter Acces Rightes
//-----------------------------------------------------------------

if(isset($is_guest) || isset($is_user))
{ header("location: $PHP_SELF?i=2"); exit; }

switch($a)
{
	//-----------------------------------------------------------------
	//  Add badword
	//-----------------------------------------------------------------

	case 1:

		//-----------------------------------------------------------------
		//  Begin Check
		//-----------------------------------------------------------------

		if(!$word){ header("location: $PHP_SELF?n=modules/badwords&i=75"); exit; }
		if(!$replacement){ header("location: $PHP_SELF?n=modules/badwords&i=76"); exit; }

		//-----------------------------------------------------------------
		//  Add the badword
		//-----------------------------------------------------------------

		$db->insertRow("badwords",array('word' => ''.$word.'','replacement' => ''.$replacement.''));

		//-----------------------------------------------------------------
		//  Write Log 
		//-----------------------------------------------------------------

		$db->insertRow("log",array('user_id' => ''.$_SESSION['id'].'','user_user' => ''.$_SESSION['username'].'','log' => ''.$language['Logs desc3'].' <b>badwords</b> the badword -> \''.$word.'\'','date' => ''.time().''));

		//-----------------------------------------------------------------
		//  Add the badword
		//-----------------------------------------------------------------

		header("location: $PHP_SELF?n=modules/badwords&i=72");

	break;

	//-----------------------------------------------------------------
	//  Delete badword
	//-----------------------------------------------------------------

	case 2:

		//-----------------------------------------------------------------
		//  Write Log
		//-----------------------------------------------------------------

		$checker = $db->getLine("SELECT * FROM badwords WHERE id = '$d'");
		$db->insertRow("log",array('user_id' => ''.$_SESSION['id'].'','user_user' => ''.$_SESSION['username'].'','log' => ''.$language['Logs desc'].' <b>badwords</b> the badword -> \''.$checker['word'].'\'','date' => ''.time().''));

		//-----------------------------------------------------------------
		//  Delete the badword
		//-----------------------------------------------------------------

		$db->deleteRow("badwords","id = '$d'");

		//-----------------------------------------------------------------
		//  Redirect when finished
		//-----------------------------------------------------------------

		header("location: $PHP_SELF?n=modules/badwords&i=73");

	break;

	//-----------------------------------------------------------------
	//  Update badwords
	//-----------------------------------------------------------------

	case 3:

		//-----------------------------------------------------------------
		//  Begin Check
		//-----------------------------------------------------------------

		foreach($word as $idx=>$val) if(!$word[$idx]){ header("location: $PHP_SELF?n=modules/badwords&i=75"); exit; }
		foreach($replacement as $idx=>$val) if(!$replacement[$idx]){ header("location: $PHP_SELF?n=modules/badwords&i=76"); exit; }

		//-----------------------------------------------------------------
		//  Save the badwords
		//-----------------------------------------------------------------
	
		foreach($word as $idx=>$val)
			$db->query("Update `badwords` set `word` = '$val' WHERE `id` = '$idx'");

		foreach($replacement as $idx=>$val)
			$db->query("Update `badwords` set `replacement` = '$val' WHERE `id` = '$idx'");

		//-----------------------------------------------------------------
		//  Write Log
		//-----------------------------------------------------------------

		$db->insertRow("log",array('user_id' => ''.$_SESSION['id'].'','user_user' => ''.$_SESSION['username'].'','log' => ''.$language['Logs desc2'].' <b>badwords</b>','date' => ''.time().''));

		//-----------------------------------------------------------------
		//  Redirect when finished
		//-----------------------------------------------------------------

		header("location: $PHP_SELF?n=modules/badwords&i=74");

	break;

	//-----------------------------------------------------------------
	//  View Badwords Form
	//-----------------------------------------------------------------

	default:

		//-----------------------------------------------------------------
		//  Load Badwords table
		//-----------------------------------------------------------------

		$badwords_db = $db->getTable("SELECT * FROM badwords");

		if($badwords_db != FALSE)
		{
			foreach($badwords_db as $idx=>$badword)
			{
				//-----------------------------------------------------------------
				//  Make Layout
				//-----------------------------------------------------------------

				$layout .= "
					<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."'>
					<td width='48%'><input type='text' name='word[{$badword['id']}]' value='{$badword['word']}' class='box' style='width:100%'></td>
					<td width='48%'><input type='text' name='replacement[{$badword['id']}]' value='{$badword['replacement']}' maxlength='50' class='box' style='width:100%'></td>
					<td width='5%'><a href='$PHP_SELF?n=modules/badwords&a=2&d={$badword['id']}'><img src='templates/$template/images/buttons/delete.gif' border='0' alt='{$language['Bad words form desc3']}'></a></td>
					</tr>";
			}
		}
		else
		{
			//-----------------------------------------------------------------
			//  Make Layout
			//-----------------------------------------------------------------

			$layout .= "
				<tr class='con1'>
				<td colspan='3'>{$language['Bad words form desc6']}</td>
				</tr>\n";
		}

		//-----------------------------------------------------------------
		// Echo the back link
		//-----------------------------------------------------------------

		echo "<table class='main' cellspacing='1' cellpadding='4'><tr class='head'><td colspan='3'>{$language['Admin name']}</td></tr><tr><td colspan='3' class='con1' onMouseOver=this.className='con3' onMouseOut=this.className='con1' onclick=window.location.href='$PHP_SELF?n=modules/admin'><a href='$PHP_SELF?n=modules/admin'> &raquo; {$language['Admin back']}</a></td></tr></table><br>";
		
		?>
			<form method="post" action="<?= $PHP_SELF ?>?n=modules/badwords">
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class="head"><td colspan="4"><?= $language['Bad words add title'] ?></td></tr>
			<tr class="bottom"><td width="45%"><?= $language['Bad words add desc'] ?></td><td width="45%"><?= $language['Bad words add desc2'] ?></td><td width="10%"><?= $language['Bad words add desc3'] ?></td></tr>
			<tr class="con1"><td><input type='text' name='word' class='box' style='width:100%'></td><td><input type='text' name='replacement' class='box' style='width:100%'></td><td><input type='submit' name='submit' style='width:100%' class='box' value='<?= $language['Bad words add desc4'] ?>'></td></tr>
			<input type="hidden" name="a" value="1">
			</table></form>
			<br>
			<form method="post" action="<?= $PHP_SELF ?>?n=modules/badwords">
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class="head"><td colspan="4"><?= $language['Bad words form title'] ?></td></tr>
			<tr class="bottom"><td><?= $language['Bad words form desc'] ?></td><td colspan="2"><?= $language['Bad words form desc2'] ?></td></tr>
			<?= $layout ?>
			</table>
			<br>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='con1'>
			<td width="50%"><?= $language['Bad words form desc4'] ?></td>
			<td width="50%" align="right"><input type='submit' name='submit' style='width:50%' class='box' value='<?= $language['Bad words form desc5'] ?>' tabindex='3'></td>
			</tr>
			<input type="hidden" name="a" value="3">
			</table></form>
		<?
}
?>